#include<cstdio>//uncle-lu
#include<cstring>
#include<vector>
#include<algorithm>
template<class T>void read(T &x)
{
	x=0;int f=0;char ch=getchar();
	while(ch<'0'||ch>'9') { f|=(ch=='-'); ch=getchar(); }
	while(ch<='9'&&ch>='0') { x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); }
	x = f ? -x : x;
	return ;
}

struct node{
	int v, val;
};
std::vector<node>son[3010];
int F[3010][3010], line[3010], cnt[3010];
int n, m;

void DFS(int x)
{
	if(x >= n-m+1)//x为叶子节点
	{
		cnt[x] = 1;
		F[x][1] = line[x];
		return ;
	}

	for (int i = 0; i < (int)son[x].size(); i++) 
	{
		int v = son[x][i].v;
		DFS(v);
		cnt[x] += cnt[v];
		for (int j = cnt[x]; j >= 0; j--) //x的叶子节点个数 01背包
			for (int k = 0; k <= std::min(j, cnt[v]); k++)
				F[x][j] = std::max(F[x][j], F[x][j-k] + F[v][k] - son[x][i].val);
	}

	return ;
}

int main()
{
	read(n);read(m);
	int temp, v, val;
	for (int i = 1; i <= n-m; i++) 
	{
		read(temp);
		for (int k = 1; k <= temp; k++) 
		{
			read(v);read(val);
			son[i].push_back((node){v, val});
		}
	}
	for (int i = n-m+1; i <= n; i++) 
		read(line[i]);

	memset(F, -0x7f7f, sizeof(F));
	for (int i = 1; i <= n; i++) 
		F[i][0] = 0;

	DFS(1);

	for (int i = m; i >= 0; i--) 
	{
		if(F[1][i]>=0)
		{
			printf("%d", i);
			break;
		}
	}

	return 0;
}
